<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改区域')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-costCode-edit">
        <input id="parentId" name="parentId" type="hidden" th:value="${costCode.parentId}"/>
        <input id="codeId" name="codeId" type="hidden" th:value="${costCode.codeId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">编码编号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="codeNum" id="codeNum" placeholder="请输入编码编号"
                       th:value="${costCode.codeNum}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">编码名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="codeName" id="codeName" placeholder="请输入编码名称"
                       th:value="${costCode.codeName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">特征：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="codeFeature" id="codeFeature" placeholder="请输入特征"
                       th:value="${costCode.codeFeature}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">单位：</label>
            <div class="col-sm-8">
                <select name="codeUnit" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="codeUnit : ${codeUnit}" th:text="${codeUnit.name}"
                            th:selected="${codeUnit.id==costCode.codeUnit}"
                            th:value="${codeUnit.id}" ></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "costCode";

    $("#form-costCode-edit").validate({
        rules: {
            onkeyup: false,
            codeNum: {
                remote: {
                    url: prefix + "/checkCodeNumUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "parentId": function () {
                            return $("input[name='parentId']").val();
                        },
                        "codeId": function () {
                            return $("input[name='codeId']").val();
                        },
                        "codeNum": function () {
                            return $.common.trim($("#codeNum").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "codeNum": {
                remote: "编码编号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-costCode-edit").serializeArray();
            $.operate.save(prefix + "/save", data);
        }
    }

</script>
</body>
</html>
